<?php
/**
 *  菜单权限管理
*/

namespace app\admin\controller;

use app\common\exception\BaseException;
use app\admin\service\MenuRole as ServiceMenuRole;
use app\facade\Basic;
use think\Request;

class MenuRole extends BaseController
{
    /**
     *  菜单列表
     */
    public function index(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);  // ID

        /* 验证 */
        //$this->validateData($param,'Menu.list');

        /* 创建列表 */
        $ServiceMenuRole = new ServiceMenuRole();
        $result = $ServiceMenuRole->list($param);
        return Basic::json($result);
    }

    /**
     *
     *  添加菜单
    */
    public function create(Request $request)
    {

        $param['creator'] = $request->operator_id;
        $param['parent_id'] = $request->param('parent_id',null);  // 父ID
        $param['btnkey'] = $request->param('btnkey',null);  // 按钮字符
        $param['name'] = $request->param('name',null);  // 名称
        $param['method'] = $request->param('method',null);
        $param['route'] = $request->param('route',null);
        $param['sort'] = $request->param('sort',0);

        /* 验证 */
      // $this->validateData($param,'Menu.create');

        /* 创建菜单 */
        $ServiceMenuRole = new ServiceMenuRole();
        $result = $ServiceMenuRole->save($param);
        return Basic::json($result);
    }

    /**
     *  更新修改菜单
    */
    public function update(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $param['parent_id'] = $request->param('parent_id',null);  // 父ID
        $param['btnkey'] = $request->param('btnkey',null);  // 按钮字符
        $param['name'] = $request->param('name',null);  // 名称
        $param['method'] = $request->param('method',null);
        $param['route'] = $request->param('route',null);
        $param['sort'] = $request->param('sort',0);

        /* 验证 */
        // $this->validateData($param,'Menu.create');

        /* 创建菜单 */
        $ServiceMenuRole = new ServiceMenuRole();
        $result = $ServiceMenuRole->save($param);
        return Basic::json($result);
    }


    /**
     *  删除菜单
    */
    public function delete(Request $request)
    {


        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);

        /* 验证 */
        // $this->validateData($param,'Menu.create');

        /* 创建菜单 */
        $ServiceMenuRole = new ServiceMenuRole();
        $result = $ServiceMenuRole->delete($param);
        return Basic::json($result);

    }


}